package com.bytenebula.asteroid.config;

import com.bytenebula.asteroid.filter.TenantFilter;
import com.bytenebula.asteroid.utils.BnTenantFactory;
import com.mybatisflex.core.tenant.TenantFactory;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TenantConfig {

    @Bean
    public FilterRegistrationBean<TenantFilter> tenantFilter() {
        FilterRegistrationBean<TenantFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new TenantFilter());
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }

    @Bean
    public TenantFactory tenantFactory(){
        return new BnTenantFactory();
    }

}
